package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.ColumnService;
import com.junzhiit.nengji.cms.web.vo.ColumnAddVO;
import com.junzhiit.nengji.cms.web.vo.ColumnEditVO;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/column")
public class ColumnController {

	@Autowired
	private ColumnService columnService;

	@ApiOperation(value = "获取所有栏目列表")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp,String sessionId) {
		return columnService.findAll(dtp,sessionId);
	}

	@ApiOperation(value = "获取所有栏目相关的模块数")
	@RequestMapping(value = "/modules/count/{columnId}", method = RequestMethod.GET)
	public ResultVO getTotalModulesCount(@PathVariable String columnId) {
		return columnService.getTotalModulesCount(columnId);
	}

	@ApiOperation(value = "获取栏目信息")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findById(@PathVariable String id) {
		return columnService.findById(id);
	}

	@ApiOperation(value = "获取栏目信息(不分页)")
	@RequestMapping(value = "/all", method = RequestMethod.GET)
	public ResultVO findNoPageAll(String sessionId) {
		return columnService.findNoPageAll(sessionId);
	}

	@ApiOperation(value = "添加栏目")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(ColumnAddVO columnAddVO,String sessionId) {
		return columnService.add(columnAddVO,sessionId);
	}

	@ApiOperation(value = "编辑栏目")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO edit(ColumnEditVO columnEditVO) {
		return columnService.edit(columnEditVO);
	}

	@ApiOperation(value = "删除栏目")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO del(String id) {
		AssertUtil.notBlank(id, "id is required");
		return columnService.del(id);
	}

}
